﻿Public Class HasQuarterState
    Implements IState
    Private _machine As GumballMachine
    Private _random As New Random()

    Public Sub New(ByVal machine As GumballMachine)
        _machine = machine
    End Sub

    Public Sub dispense() Implements IState.dispense
        Console.WriteLine("No gumball dispensed")
    End Sub

    Public Sub ejectQuarter() Implements IState.ejectQuarter
        Console.WriteLine("Quarter returned")
        _machine.CurrentState = _machine.NoQuarterState
    End Sub

    Public Sub insertQuarter() Implements IState.insertQuarter
        Console.WriteLine("You can't insert another quarter")
    End Sub

    Public Sub turnCrank() Implements IState.turnCrank
        Console.WriteLine("You turned...")
        Dim winner As Integer = _random.Next(10)
        If winner = 0 Then
            _machine.CurrentState = _machine.WinnerState
        Else
            _machine.CurrentState = _machine.SoldState
        End If
    End Sub

    Public Overrides Function ToString() As String
        Return "waiting for turn of crank"
    End Function
End Class
